package com.aos.erp.gov.ex.web.rpc;

import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.gov.ex.model.GovExConfig;
import com.aos.erp.gov.ex.model.GovExConfigItem;
import com.aos.erp.gov.ex.model.ro.GovExConfigDTO;
import com.aos.erp.gov.ex.service.GovExConfigItemService;
import com.aos.erp.gov.ex.service.GovExConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@RestController("RPCGovExConfigController")
@RequestMapping("/service/gov/ex/config")
@Api("RPCGovExConfigController")
public class GovExConfigController {

    @Resource
    private GovExConfigService govExConfigService;
    @Resource
    private GovExConfigItemService itemService;

    @GetMapping("/getConfigDetail")
    @ApiOperation(value = "获取，某省市的配置详情")
    public GovExConfigDTO getConfigDetail(String provinceCode, String cityCode) {
        GovExConfig config = govExConfigService.getByCode(provinceCode, cityCode);
        if (config != null) {
            GovExConfigDTO dto = new GovExConfigDTO();
            BeanUtils.copyProperties(config, dto);
            List<GovExConfigItem> itemList = itemService.getByConfig(config.getId(), config.getConfigType());
            dto.setConfigItemList(itemList);
            return dto;
        }
        return null;
    }


    @GetMapping("/getConfig")
    @ApiOperation(value = "获取，某省市的配置")
    public ResultEntity<GovExConfig> getConfig(String provinceCode, String cityCode) {
        GovExConfig config = govExConfigService.getByCode(provinceCode, cityCode);
        return ResultEntity.success(config);
    }

}